import request from '@/utils/request'
import { User } from './type'

enum API {
  // 获取全部已有用户账号信息
  ALLUSER_URL = '/admin/user/allAdmin/',
  // 添加一个新的用户账号
  ADDUSER_URL = '/admin/user/save',
  // 更新已有的用户账号信息
  UPDATEUSER_URL = '/admin/user/update',
  //获取全部职位,当前账号拥有的职位接口
  ALLROLE_URL = '/admin/user/toAssign/',
  // 给已有的用户分配角色接口
  SETROLE_URL = '/admin/user/doAssignRole',
  // 删除某一个账号
  DELETEUSER_URL = '/admin/user/remove/',
  // 批量删除
  DELETEALLUSER_URL = '/admin/user/batchRemove',
  // 查询重复账号
  CHECKUSER_URL = '/admin/user/repeatUsername/',
}

// 获取全部已有用户账号信息
export const reqAllUser = (page: number, limit: number, username: string) => {
  return request.get<any, any>(
    API.ALLUSER_URL + `${page}/${limit}/?username=${username}`,
  )
}
// 添加用户与更新已有用户账号信息
export const reqAddOrUpdateUser = (data: User) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data)
  }
}
// 获取全部职位,当前账号拥有的职位接口
export const reqAllRole = (id: number) => {
  return request.get<any, any>(API.ALLROLE_URL + id)
}
// 分配职位
export const reqSetUserRole = (data: any) => {
  return request.post<any, any>(API.SETROLE_URL, data)
}
// 删除某一个账号
export const reqRemoveUser = (id: number) => {
  return request.delete<any, any>(API.DELETEUSER_URL + id)
}
// 批量删除
export const reqSelectUser = (idList: number[]) => {
  return request.post<any, any>(API.DELETEALLUSER_URL, { id: idList })
}
// 查询重复账号
export const reqCheckUser = (username: string) => {
  return request.get<any, any>(API.CHECKUSER_URL + username)
}
